﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BotonJXC.Entity;
using NHibernate;
using NHibernate.Criterion;
using BotonJXC.Util;

namespace BotonJXC.DAO
{
    public class PickingsDao: NHibernateDao<Pickings, int>
    {
        public void SavePickings(Pickings Pickings)
        {
            ITransaction trans = HBHelper.BeginTransaction();
            try
            {

                base.Save(Pickings);
                trans.Commit();
            }
            catch (HibernateException ex)
            {
                trans.Rollback();
                throw ex;

            }
            finally
            {
                HBHelper.Close();
            }

        }

        public void updatePickings(Pickings Pickings)
        {
            ITransaction trans = HBHelper.BeginTransaction();
            try
            {

                base.Update(Pickings);
                trans.Commit();
            }
            catch (HibernateException ex)
            {
                trans.Rollback();
                throw ex;

            }
            finally
            {
                HBHelper.Close();
            }

        }

        public PageModel<Pickings> FindPage(string PickingsSn, DateTime begintime, DateTime endtime, int start, int count)
        {
            List<ICriterion> criterions = new List<ICriterion>();
            if (Utils.IsNotBlank(PickingsSn))
            {
                criterions.Add(Restrictions.Eq("PickingSn", PickingsSn));
            }
            if (begintime != null)
            {
                criterions.Add(Restrictions.Ge("CreateTime", begintime));
            }
            if (endtime != null)
            {
                criterions.Add(Restrictions.Le("CreateTime", endtime));
            }
            Order order = new Order("CreateTime", false);
            return base.FindByPage(criterions.ToArray(), order, start, count);
        }
    }
}
